package cn.qicaiwang.open.websocket.common;

import org.springframework.web.socket.WebSocketSession;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

public class Constant {
    /** concurrent包的线程安全Set，用来存放每个客户端对应的WebSocket对象。 */
    public static ConcurrentHashMap<String, WebSocketSession> pool = new ConcurrentHashMap<String, WebSocketSession>();

    public static final String WS_CONTEXT_HOLDER = "WEBSOCKET_CONTEXT_HOLDER";

    public static List<String> onlines() {
        Enumeration<String> keys = Constant.pool.keys();
        List<String> list = new ArrayList<>();
        while (keys.hasMoreElements()){
            String key = keys.nextElement();
            list.add(key);
        }
        return list;
    }
}
